package com.flink.streaming.web.controller.web;


import com.alibaba.fastjson.JSONObject;
import com.flink.streaming.web.model.param.AzKaBanParam;
import com.flink.streaming.web.model.vo.AzkanbanOfflineSQLVO;
import com.flink.streaming.web.model.vo.PageVO;
import com.flink.streaming.web.service.AzKaBanSqlService;
import com.github.pagehelper.Page;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

@Slf4j
@Controller
@RequestMapping("/admin")
public class AzKaBanSqlController extends BaseController {

    @Autowired
    private AzKaBanSqlService azKaBanSqlService;



    @RequestMapping("/azKaBanSqlList")
    public String list(ModelMap modelMap, AzKaBanParam azKaBanParam) {

        // 分页查询
        Page<AzkanbanOfflineSQLVO> page = azKaBanSqlService.listPage(azKaBanParam);
        PageVO pageVO = new PageVO();
        pageVO.setPageNum(page.getPageNum());
        pageVO.setPages(page.getPages());
        pageVO.setPageSize(page.getPageSize());
        pageVO.setTotal(page.getTotal());

        // 跳转page 页面
        modelMap.put("pageVO", pageVO);
        modelMap.put("azKabanParam", azKaBanParam);
        modelMap.put("azKabanResp", page.getResult());
        return "screen/azkaban/listPage";
    }

    @RequestMapping("/azKaBanSqlAddBatchPage")
    public String addPage(ModelMap modelMap) {
        modelMap.put("active", "addPage");
        modelMap.put("open", "config");
        return "screen/azkaban/addBatchPage";
    }


    @RequestMapping("/azKaBanSqlEditBatchPage")
    public String editBatchPage(ModelMap modelMap, Long id) {
        AzkanbanOfflineSQLVO sqlvo = azKaBanSqlService.queryById(id);
        modelMap.put("extParas", JSONObject.parseObject(sqlvo.getExtParas()));
        modelMap.put("azkanbanOfflineSQLVO", sqlvo);
        return "screen/azkaban/editPage";
    }
}
